<?php
class ModelTotalTax extends Model {
	public function getTotal(&$total_data, &$total, &$taxes, $status = 0) {
		if ($this->config->get('tax_status')) {
			foreach ($taxes as $key => $value) {
				if ($value > 0) {
					$tax_classes = $this->tax->getDescription($key);
					
					foreach ($tax_classes as $tax_class) {
						$rate = $this->tax->getRate($key);
						// Price include tax
						//$tax = abs($total - ($total / (1 + $rate / 100)));  
                        $tax = $total_data['subtotal']['value'] * 0.2; // Price include 25% tax
						
						//Modify to new rule: tax base on total
						if($total_data['total']['value'] > 0){
							$shipping = isset($total_data['shipping']['value']) ? $total_data['shipping']['value'] : 0;
							$tax = ($total_data['total']['value'] - $shipping) * 0.2;
						}
						else{
							$tax = $total_data['subtotal']['value'] * 0.2;
						}
						
                        // Price does not include tax
                        //$tax = $value * ($tax_class['rate'] / $rate); 
						
						$total_data['tax'] = array(
	    					'title'      => $tax_class['description'] . ':', 
	    					'text'       => $this->currency->formatPrice($tax), 
	    					'value'      => $tax,
							'sort_order' => $this->config->get('total_sort_order') - 2, //$this->config->get('tax_sort_order'),
							'total_code' => '',
	    				);			         
					}
				}
			}
		}
	}
	
	public function getTotalTax(&$total_data, &$total, &$taxes) {
		if ($this->config->get('tax_status')) {
			foreach ($taxes as $key => $value) {
				if ($value > 0) {
					$tax_classes = $this->tax->getDescription($key);
					
					foreach ($tax_classes as $tax_class) {
						$rate = $this->tax->getRate($key);
						
						$tax = $value * ($tax_class['rate'] / $rate);
						
						$total_data[] = array(
	    					'title'      => $tax_class['description'] . ':', 
	    					'text'       => $this->currency->format($tax),
	    					'value'      => $tax,
							'sort_order' => $this->config->get('tax_sort_order')
	    				);
			
						$total += $tax;
					}
				}
			}
		}
	}
}
?>